package com.caolei1992.web.constant;

import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * 上传配置
 *
 * @author xbuding
 * @version 1.0
 * @since 2019/4/9
 */
public class UploadConstant {

    /**
     * 上传类型
     */
    public static class UploadType {

        private final static Map<String, String> MAP = ImmutableMap.<String, String>builder()
                /*
                  头像的图片
                 */
                .put("AVATAR_IMAGE", "/image/avatar/%s")
                /*
                 * 展览的素材
                 */
                .put("EXPO_MATERIAL", "/image/expo/%s")
                /*
                 * 视频
                 */
                .put("EXPO_VIDEO", "/video/expo/%s")
                .build();

        /**
         * 获取上传保存的地址
         *
         * @param type
         * @param fileName
         * @return
         */
        public static String getUploadPath(String type, String fileName) {
            if (StringUtils.isNotEmpty(type) && MAP.containsKey(type)) {
                String path = MAP.get(type);
                return String.format(path, fileName);
            } else {
                throw new RuntimeException("未定义类型");
            }
        }
    }

}
